package com.ssm.springboot.web.controller;

import com.ssm.springboot.ExceptionHander.MyException;
import com.ssm.springboot.pojo.Data;
import com.ssm.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author
 * @create 2018-05-25 12:04
 **/
@RestController
public class IndexController {

    @Autowired
    UserService userService;

    @Value("${xql.name}")
    private String name;
    @RequestMapping("/girl")
    public String get(){
        System.out.println(name+"明天你");
        return  name+"风一样的女子";
    }

    @RequestMapping("/show")
    public Object show(){
        Map<Object, Object> map = new HashMap<>();
        map.put("001","卧底");
        map.put("002","间谍");
        map.put("003","特工");
        List<Map<Object, Object>> list = new ArrayList<>();
        list.add(map);
        Map<Object, Object> low = new HashMap<>();
        low.put("001","杀手");
        low.put("002","刺客");
        low.put("003","盗贼");
        list.add(low);
        return  list;
    }

    @GetMapping("/getList")
    public  List<Data> getList(int age){

        List<Data> list = userService.getList(age);
       return list;
    }
    @RequestMapping("/test")
    public  String get(@RequestParam("name") String name){

        return "name:"+name;
    }
    @RequestMapping(value = "/insert" ,produces="text/plain;charset=UTF-8")
    public void  insert(HttpServletRequest request) throws MyException  {
        Data data = new Data();
        String test = request.getParameter("test");

//        int b=1/0;
//        System.out.println("222222222"+b);
        data.setId(001);

        data.setAge(23);
        String name="试管倒退";
        data.setName(test);
        userService.insert(data);
        throw new MyException("新消息");
    }
    @RequestMapping("/json")
    public String json() throws MyException {
        throw new MyException("cuo无得处理");
    }
}
